<
%@ page contentType="text/html;charset=UTF-8" %>
<script>
    $(document).ready(function() {
    $('#resourceTable').bootstrapTable({

        //请求方法
        method: 'get',
        //类型json
        dataType: "json",
        //显示刷新按钮
        showRefresh: true,
        //显示切换手机试图按钮
        showToggle: true,
        //显示 内容列下拉框
        showColumns: true,
        //显示到处按钮
        showExport: true,
        //显示切换分页按钮
        showPaginationSwitch: true,
        //最低显示2行
        minimumCountColumns: 2,
        //是否显示行间隔色
        striped: true,
        //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        cache: false,
        //是否显示分页（*）
        pagination: true,
        //排序方式
        sortOrder: "asc",
        //初始化加载第一页，默认第一页
        pageNumber: 1,
        //每页的记录行数（*）
        pageSize: 10,
        //可供选择的每页的行数（*）
        pageList: [10, 25, 50, 100],
        //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
        url: "${ctx}/tms/resource/data",
        //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
        //queryParamsType:'',
        ////查询参数,每次调用是会带上这个参数，可自定义
        queryParams: function (params) {
            var searchParam = $("#searchForm").serializeJSON();
            searchParam.pageNo = params.limit === undefined ? "1" : params.offset / params.limit + 1;
            searchParam.pageSize = params.limit === undefined ? -1 : params.limit;
            searchParam.orderBy = params.sort === undefined ? "" : params.sort + " " + params.order;
            return searchParam;
        },
        //分页方式：client客户端分页，server服务端分页（*）
        sidePagination: "server",
        contextMenuTrigger: "right",//pc端 按右键弹出菜单
        contextMenuTriggerMobile: "press",//手机端 弹出菜单，click：单击， press：长按。
        contextMenu: '#context-menu',
        onContextMenuItem: function (row, $el) {
            if ($el.data("item") == "edit") {
                edit(row.id);
            } else if ($el.data("item") == "delete") {
                jp.confirm('确认要删除该承运商记录吗？', function () {
                    jp.loading();
                    jp.get("${ctx}/tms/resource/delete?id=" + row.id, function (data) {
                        if (data.success) {
                            $('#resourceTable').bootstrapTable('refresh');
                            jp.success(data.msg);
                        } else {
                            jp.error(data.msg);
                        }
                    })

                });

            }
        },

        onClickRow: function (row, $el) {
        },
        rowStyle: function (row, index) {
            if (row.isrepeat == "1") {
                return {css: {"background-color": "yellow"}}
            } else {
                return {css: {"background-color": "white"}}
            }
        },

        columns: [{
            checkbox: true

        }
            , {
                field: 'name',
                title: '公司名称',
                sortable: true
                , formatter: function (value, row, index) {
                    return "<a href='javascript:edit(\"" + row.id + "\")'>" + value + "</a>";
                }

            }
            , {
                field: 'contacts',
                title: '联系人',
                sortable: true

            }
            , {
                field: 'companyPhone',
                title: '电话',
                sortable: true

            }
            , {
                field: 'phone',
                title: '手机',
                sortable: true

            }
            , {
                field: 'park',
                title: '所属园区',
                sortable: true

            }
            , {
                field: 'companyAddress',
                title: '公司地址',
                sortable: true

            }
            , {
                field: 'authenticationType',
                title: '认证类型',
                sortable: true,
                formatter: function (value, row, index) {
                    var valueArray = value.split(",");
                    var labelArray = [];
                    for (var i = 0; i < valueArray.length - 1; i++) {
                        labelArray[i] = jp.getDictLabel(${fns:toJson(fns:getDictList('authentication_type'))}, valueArray[i], "-");
                    }
                    return labelArray.join(",");
                }

            }
            , {
                field: 'certificationDate',
                title: '认证日期',
                sortable: true

            }
            , {
                field: 'expirationDate',
                title: '认证到期日期',
                sortable: true

            }
            , {
                field: 'insuranceDate',
                title: '保险到期日期',
                sortable: true

            }
            , {
                field: 'cooperationType',
                title: '合同类型',
                sortable: true,
                formatter: function (value, row, index) {
                    return jp.getDictLabel(${fns:toJson(fns:getDictList('yes_no'))}, value, "-");
                }

            }
            , {
                field: 'cooperationDate',
                title: '合同到期日期',
                sortable: true

            }
            , {
                field: 'brand',
                title: '软件品牌',
                sortable: true

            }
            , {
                field: 'idCard',
                title: '身份证号',
                sortable: true

            }
            , {
                field: 'registerDate',
                title: '公司注册时间',
                sortable: true

            }
            , {
                field: 'companySummary',
                title: '公司简介',
                sortable: true

            }
            , {
                field: 'top',
                title: '是否置顶',
                sortable: true,
                formatter: function (value, row, index) {
                    return jp.getDictLabel(${fns:toJson(fns:getDictList('top'))}, value, "-");
                }

            }
            , {
                field: 'topDate',
                title: '置顶到期日期',
                sortable: true

            }
            , {
                field: 'isrepeat',
                title: '是否重复',
                visible: false,
                sortable: true

            }
        ]

    });


    if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端


    $('#resourceTable').bootstrapTable("toggleView");
}

    $('#resourceTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
    'check-all.bs.table uncheck-all.bs.table', function () {
    $('#remove').prop('disabled', ! $('#resourceTable').bootstrapTable('getSelections').length);
    $('#exportresource').prop('disabled', ! $('#resourceTable').bootstrapTable('getSelections').length);
    $('#edit').prop('disabled', $('#resourceTable').bootstrapTable('getSelections').length!=1);
});

    $("#btnImport").click(function(){
    jp.loading('  正在导入，请稍等...');
    jp.open({
    type: 1,
    area: [500, 300],
    title:"导入数据",
    content:$("#importBox").html() ,
    btn: ['下载模板','确定', '关闭'],
    btn1: function(index, layero){
    window.location='${ctx}/tms/resource/import/template';
},
    btn2: function(index, layero){
    var inputForm =top.$("#importForm");
    var top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
    inputForm.onsubmit = function(){
    jp.loading('  正在导入，请稍等...');
}
    inputForm.submit();
    jp.close(index);
},

    btn3: function(index){
    jp.close(index);
}
});
});

    $("#search").click("click", function() {// 绑定查询按扭
    $('#resourceTable').bootstrapTable('refresh');
});

    $("#reset").click("click", function() {// 绑定查询按扭
    $("#searchForm  input").val("");
    $("#searchForm  select").val("");
    $("#searchForm  .select-item").html("");
    $('#resourceTable').bootstrapTable('refresh');
});


});

    function getIdSelections() {
    return $.map($("#resourceTable").bootstrapTable('getSelections'), function (row) {
    return row.id
});
}

    function deleteAll(){

    jp.confirm('确认要删除该承运商记录吗？', function () {
        jp.loading();
        jp.get("${ctx}/tms/resource/deleteAll?ids=" + getIdSelections(), function (data) {
            if (data.success) {
                $('#resourceTable').bootstrapTable('refresh');
                jp.success(data.msg);
            } else {
                jp.error(data.msg);
            }
        })

    })
}
    function add(){
    jp.openDialog('新增承运商', "${ctx}/tms/resource/form", '800px', '500px', $('#resourceTable'));
}
    function edit(id){//没有权限时，不显示确定按钮
    if(id == undefined){
    id = getIdSelections();
}
    <shiro:hasPermission name="tms:resource:edit">
    jp.openDialog('编辑承运商', "${ctx}/tms/resource/form?id=" + id,'800px', '500px', $('#resourceTable'));
    </shiro:hasPermission>
    <shiro:lacksPermission name="tms:resource:edit">
    jp.openDialogView('查看承运商', "${ctx}/tms/resource/form?id=" + id,'800px', '500px', $('#resourceTable'));
    </shiro:lacksPermission>
    }
    function exportresource(id){
    window.location.href = "${ctx}/tms/resource/exportresource?id=" + id;
}
    function exportresourceall(){
    window.location.href = "${ctx}/tms/resource/exportresource";
}

</script>